#include "Level1.h"

Level1::Level1(void)
{
}

Level1::~Level1(void)
{
}

void Level1::InitLevel(Character *player, QUESTTYPE questType, int difficulty)
{
	if(!init)
	{
		// FIRST FLOOR //

		//Base floor
		this->CreatePlatform(Vector3D(-350, 497, 0), 20, 1, Platform::GRASS, 1.0, 1.0, 1.0);

		//Right boundary
		this->CreatePlatform(Vector3D(-490, 415, 0), 5, 1, Platform::TREE, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(-525, 415, 0), 5, 1, Platform::TREE, 1.0, 1.0, 1.0);

		//Block
		this->CreatePlatform(Vector3D(300, 461, 0), 1, 1, Platform::GRASS, 1.0, 1.0, 1.0);

		//AI
		this->CreatePlatform(Vector3D(500, 460, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);

		//Hay
		this->CreatePlatform(Vector3D(650, 465, 0), 1, 1, Platform::HAY, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(650, 430, 0), 1, 1, Platform::HAY, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(650, 395, 0), 1, 1, Platform::HAY, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(715, 465, 0), 1, 1, Platform::HAY, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(715, 430, 0), 1, 1, Platform::HAY, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(715, 395, 0), 1, 1, Platform::HAY, 1.0, 1.0, 1.0);

		//Trees
		this->CreatePlatform(Vector3D(785, 415, 0), 7, 1, Platform::TREE, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(820, 415, 0), 7, 1, Platform::TREE, 1.0, 1.0, 1.0);
		
		// SECOND FLOOR //
		//2nd Floor
		this->CreatePlatform(Vector3D(800, 375, 0), 9, 1, Platform::GRASS, 1.0, 1.0, 1.0);

		//AI
		this->CreatePlatform(Vector3D(1000, 335, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);

		//Hay
		this->CreatePlatform(Vector3D(1200, 340, 0), 1, 1, Platform::HAY, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(1265, 340, 0), 1, 1, Platform::HAY, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(1232, 305, 0), 1, 1, Platform::HAY, 1.0, 1.0, 1.0);

		//Lamp
		this->CreatePlatform(Vector3D(1340, 240, 0), 1, 1, Platform::LAMP, 1.0, 1.0, 1.0);

		// THIRD FLOOR //
		//3rd level floor
		this->CreatePlatform(Vector3D(710, 270, 0), 7, 1, Platform::GRASS, 1.0, 1.0, 1.0);

		//Stairs
		this->CreatePlatform(Vector3D(710, 235, 0), 4, 1, Platform::GRASS, 1.0, 1.0, 1.0);	//First row
		this->CreatePlatform(Vector3D(710, 200, 0), 3, 1, Platform::GRASS, 1.0, 1.0, 1.0);	//Second row
		this->CreatePlatform(Vector3D(710, 165, 0), 2, 1, Platform::GRASS, 1.0, 1.0, 1.0);	//Third row

		//AI
		this->CreatePlatform(Vector3D(930, 195, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(790, 125, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);

		// FOURTH FLOOR //
		//4th level floor
		this->CreatePlatform(Vector3D(230, 130, 0), 8, 1, Platform::GRASS, 1.0, 1.0, 1.0);

		//AI
		this->CreatePlatform(Vector3D(300, 90, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(600, 90, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);

		//Stairs
		this->CreatePlatform(Vector3D(130, 90, 0), 1, 1, Platform::GRASS, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(25, 40, 0), 1, 1, Platform::GRASS, 1.0, 1.0, 1.0);

		//Boundary
		this->CreatePlatform(Vector3D(-100, 300, 0), 1, 9, Platform::BOUNDARY, 1.0, 1.0, 1.0);
		
		// FIFTH FLOOR //
		//5th floor
		this->CreatePlatform(Vector3D(140, -10, 0), 31, 1, Platform::GRASS, 1.0, 1.0, 1.0);

		//Hay
		this->CreatePlatform(Vector3D(500, -45, 0), 10, 1, Platform::HAY, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(630, -78, 0), 8, 1, Platform::HAY, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(720, -111, 0), 6, 1, Platform::HAY, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(800, -144, 0), 4, 1, Platform::HAY, 1.0, 1.0, 1.0);

		// AI //
		//Floor row
		this->CreatePlatform(Vector3D(650, -45, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(800, -45, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(950, -45, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(1100, -45, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);
		//1st row
		this->CreatePlatform(Vector3D(550, -85, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(875, -85, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(1000, -85, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);
		//2nd row
		this->CreatePlatform(Vector3D(800, -120, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(1000, -120, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);
		//3rd row
		this->CreatePlatform(Vector3D(850, -155, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);
		//4th row
		this->CreatePlatform(Vector3D(925, -190, 0), 1, 1, Platform::AISPAWNPOINT, 1.0, 1.0, 1.0);

		//Trees
		this->CreatePlatform(Vector3D(1200, -92, 0), 5, 1, Platform::TREE, 1.0, 1.0, 1.0);

		//SIXTH FLOOR//
		//6th floor
		this->CreatePlatform(Vector3D(1200, -135, 0), 5, 1, Platform::GRASS, 1.0, 1.0, 1.0);

		//Boundary if the level is not protect
		if (questType != Level::PROTECT)
		{
			this->CreatePlatform(Vector3D(1200, -270, 0), 1, 1, Platform::LAMP, 1.0, 1.0, 1.0);
		}

		//End boundary
		this->CreatePlatform(Vector3D(2000, -145, 0), 1, 1, Platform::LAMP, 1.0, 1.0, 1.0);
		
		//Special spawn
		this->CreatePlatform(Vector3D(1600, -45, 0), 1, 1, Platform::SPECIALSPAWN, 1.0, 1.0, 1.0);
		this->CreatePlatform(Vector3D(1900, -45, 0), 1, 1, Platform::SPECIALSPAWN, 1.0, 1.0, 1.0);

		Level::InitLevel(player, questType, difficulty);

		init = true;
	}
}

void Level1::RenderLevel(void)
{
	Level::RenderLevel();

	if (player->Get_Character_Position().x >= -100 && player->Get_Character_Position().x <= 49 &&
		player->Get_Character_Position().y <= 560 && player->Get_Character_Position().y >= 400)
	{
		if (QuestType == Level::COLLECT)
		{
			glColor3f(1.0f, 0.0f, 0.0f);
			freetype::print(our_font, 20, 480, "Mission:\nCollect materials \nby killing enemies");
		}
		else if(QuestType == Level::HUNT)
		{
			glColor3f(1.0f, 0.0f, 0.0f);
			freetype::print(our_font, 20, 480, "Mission:\nKill the enemies");
		}
		else if(QuestType == Level::PROTECT)
		{
			glColor3f(1.0f, 0.0f, 0.0f);
			freetype::print(our_font, 20, 480, "Mission:\nFind the NPC \nand protect him");
		}
	}

	if(player->Get_Character_Position().x >= -50 && player->Get_Character_Position().x <= 49 &&
	player->Get_Character_Position().y <= 560 && player->Get_Character_Position().y >= 400)
	{
		glColor3f(0.0f, 0.0f, 0.0f);
		freetype::print(our_font, 250, 330, "Use arrow keys to move!");
	}

	else if(player->Get_Character_Position().x >= 50 && player->Get_Character_Position().x <= 300 &&
	player->Get_Character_Position().y <= 560 && player->Get_Character_Position().y >= 400)
	{
		glColor3f(0.0f, 0.0f, 0.0f);
		freetype::print(our_font, 250, 350, "Press space to jump!");
	}

	else if(player->Get_Character_Position().x >= 350 && player->Get_Character_Position().x <= 550 &&
	player->Get_Character_Position().y <= 560 && player->Get_Character_Position().y >= 400)
	{
		glColor3f(0.0f, 0.0f, 0.0f);
		freetype::print(our_font, 250, 350, "Press 'Z' to attack!\n Press 'X' to defend!");
	}

	else if(player->Get_Character_Position().x >= 850 && player->Get_Character_Position().x <= 1150 &&
	player->Get_Character_Position().y <= 400 && player->Get_Character_Position().y >= 200)
	{
		glColor3f(0.0f, 0.0f, 0.0f);
		freetype::print(our_font, 150, 250, "Press 'I' to open inventory!");
	}
}

bool Level1::UpdateLevel(float elapsed)
{
	return Level::UpdateLevel(elapsed);
}